Introducing TensorFlow Similarity — The TensorFlow Blog
TensorFlow Similarity’s built-in Approximate Nearest Neighbor indexing system, which relies on the NMSLIB,
Beside accuracy and retrieval speed, the other major advantage of similarity models is that they allow you to add an unlimited new number of classes to the index without having to retrain. Instead you only need to compute the embeddings for representative items of the new classes and add them to the index. This ability to dynamically add new classes is particularly useful when tackling problems where the number of distinct items is unknown ahead of time, constantly changing, or is extremely large. An example of this would be enabling users to discover newly released music that is similar to songs they have liked in the past.
# Embedding output layer with L2 norm
from tensorflow_similarity.layers import MetricEmbedding
# Specialized metric loss
from tensorflow_similarity.losses import MultiSimilarityLoss
model.fitしたらmodel.indexでindexingしてmodel.singl_lookupで検索できる簡単さ
Triplet Loss
PN Loss
Multi Sim Loss
Circle Loss
from tensorflow_similarity.visualization import projector # allows to interactively explore the samples in 2D space
これnotebookでもつかえて便利そう